<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
    protected $result;
    protected $pagination;
    
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
       $model = $this->getModel();
       $aut = new bgAuthorize();
       
        switch(JRequest::getVar('task')){
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                JToolBarHelper::title( '質問情報作成', 'info.png' );
                JToolBarHelper::save('save','登録');
                JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('add');
                
                break;
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }
                else{
                    die("データは見つかりませんでした");
                }
                JToolBarHelper::title( '質問編集', 'info.png' );
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('edit');
                break;
                
            case 'add':
            	JToolBarHelper::title( '質問作成', 'info.png' );
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('add');
            	break;
            	    
            default :
                $this->result = &$model->getQUES();
                $this->pagination = &$model->getPagination();
            	JToolBarHelper::title( '質問管理', 'info.png' );
                if($aut->checkAdd()){
                    JToolBarHelper::addNew('add','作成');
                }
                if($aut->checkEdit()){
            	   JToolBarHelper::editList('edit', '編集');
                }
                if($aut->checkDelete()){
            	   JToolBarHelper::deleteList('', 'remove','削除');
                }
                
                $this->setLayout('default');
		}
        
		parent::display();
	}
}




